package cn.glc.daily.life.model.dto;

import cn.glc.daily.life.model.enums.LoginTypeEnums;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Arrays;

/**
 * 登录对象
 *
 * @author simon
 * @date 2020/9/21 11:43
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
@Data
public class LoginDto implements Serializable {

    private static final long serialVersionUID = 5182725413868853703L;
    /**
     * 账号/手机号/邮箱
     */
    @ApiModelProperty(value = "账号", example = "账号")
    @NotBlank(message = "账号不能为空")
    private String identify;
    /**
     * 密码/验证码
     */
    @ApiModelProperty(value = "密码", example = "密码")
    @NotBlank(message = "密码不能为空")
    private String credential;
    /**
     * 登录类型
     */
    @ApiModelProperty(value = "登录类型", example = "登录类型")
    private LoginTypeEnums type;

    public void setType(String type) {
        this.type = Arrays.stream(LoginTypeEnums.values()).filter(loginTypeEnums -> loginTypeEnums.getName().equals(type)).findFirst().orElse(null);
    }

    public void setType(LoginTypeEnums type) {
        this.type = type;
    }
}
